home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: December 8/2000
- // Author: jdc rendering
- //
- // Description:
- //
- // This file contains the procedures which implement a portable (can be
- // used anywhere) user interface for viewing collections of nodes in the
- // current Maya scene using a graphical layout. This file also contains
- // the procedures used to manipulate that user interface once it has been
- // created.
- //
-
- // ---------------------------------------------------------------------------
- // Special names and things like that
- //
- // "collectionForm": the name of the form which contains the graph
- //
-
- // ---------------------------------------------------------------------------
- // Local procedures
- //
-
- global string $gCollectionUILookupTable[];
- global int $gCollectionUILookupTableCreated = false;
-
- proc createCollectionUILookupTable()
- {
- //
- // Description:
- // This procedure is called every time the user creates a collectionUI
- // component, but only has any effect the first time it is called.
- // This procedure initializes the string array $gCollectionUILookupTable[]
- // for use as a lookup table. The lookup table will contain information
- // about all collectionUI components which exist in the current Maya
- // session.
- //
-
- global string $gCollectionUILookupTable[];
- global int $gCollectionUILookupTableCreated;
-
- if (!$gCollectionUILookupTableCreated)
- {
- // The lookup table has not yet been initialized, so we will do so now.
- //
- string $columns[];
-
- $columns[0] = "collectionUI";
- $columns[1] = "hypershadeName";
- $columns[2] = "popupMenuScript";
- $columns[3] = "filter";
-
- lookupTable($gCollectionUILookupTable, $columns);
- $gCollectionUILookupTableCreated = true;
- }
- }
-
- proc registerCollectionUI(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure is used to register a collectionUI component by entering
- // it as a row in the lookup table which contains information about all
- // collectionUI components that currently exist in Maya.
- // The row created is initially blank except for the collectionUI name.
- // Further information about the collectionUI component must be
- // subsequently added to the lookup table.
- //
-
- global string $gCollectionUILookupTable[];
- string $row[];
-
- $row[0] = $collectionUI;
- $row[1] = "";
- $row[2] = "";
- $row[3] = "";
-
- lookupTableAddRow($gCollectionUILookupTable, $row);
- }
-
- proc registerHypershadeName(
- string $collectionUI,
- string $hypershadeName)
- {
- //
- // Description:
- // This procedure associates the hypershadeName with the collectionUI
- // in the lookup table.
- //
-
- global string $gCollectionUILookupTable[];
-
- // ASSUMPTION:
- // We assume that a row already exists for this collectionUI, as it should
- // have been created by a call to registerCollectionUI() as the UI was being
- // created.
- //
- lookupTableEdit(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "hypershadeName",
- $hypershadeName);
- }
-
- proc string lookupHypershadeName(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure looks up the hypershade name associated with the
- // specified collectionUI name in the lookup table.
- //
- // Returns:
- // The hypershade name, if one is associated with the specified
- // collection UI name.
- // Otherwise: "".
- //
-
- global string $gCollectionUILookupTable[];
-
- return (lookupTableLookup(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "hypershadeName"));
- }
-
- proc string generateUniqueHypershadeName()
- {
- //
- // Description:
- // This procedure is usually called just before creating a new hypershade
- // for a collectionUI.
- // This procedure generates a unique name for a hypershade by
- // creating a string of the form collection#HyperShadeEd and incrementing
- // the # part until no hypershade by that name exists.
- //
- // Returns:
- // A unique name by which a hypershade can be created.
- //
-
- int $i = 1;
- while (`hyperGraph -exists ("collection" + $i + "HyperShadeEd")`)
- {
- $i++;
- }
- return ("collection" + $i + "HyperShadeEd");
- }
-
- proc registerFilter(
- string $collectionUI,
- string $filter)
- {
- //
- // Description:
- // This procedure associates the filter with the collectionUI
- // in the lookup table.
- //
-
- global string $gCollectionUILookupTable[];
-
- // ASSUMPTION:
- // We assume that a row already exists for this collectionUI, as it should
- // have been created by a call to registerCollectionUI() as the UI was being
- // created.
- //
- lookupTableEdit(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "filter",
- $filter);
- }
-
- // ---------------------------------------------------------------------------
- // Global procedures
- //
-
- global proc string collectionUIHypershadeName(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure returns the name of the hypershade editor associated
- // with the specified collectionUI component.
- //
-
- return lookupHypershadeName($collectionUI);
- }
-
- global proc string collectionUIFilter(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure looks up the filter associated with the
- // specified collectionUI name in the lookup table.
- //
- // Returns:
- // The hypershade name, if one is associated with the specified
- // collection UI name.
- // Otherwise: "".
- //
-
- global string $gCollectionUILookupTable[];
-
- return (lookupTableLookup(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "filter"));
- }
-
- global proc int collectionUIIsManaged(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure is used to query whether the overall layout of the
- // specified collectionUI component is managed or not.
- //
- // Returns:
- // This procedure returns true if the overall layout is managed, false if
- // not.
- //
-
- return `formLayout -query -manage $collectionUI`;
- }
-
- global proc collectionUIManage(
- string $collectionUI,
- int $manage)
- {
- //
- // Description:
- // This procedure lets the caller manage or unmanage the overall layout of
- // the specified collectionUI component.
- //
-
- formLayout -edit -manage $manage $collectionUI;
- }
-
- global proc string collectionUIPopupMenuScript(
- string $collectionUI)
- {
- //
- // Description:
- // This procedure looks up the name of the popup menu script associated
- // with the specified collectionUI component.
- //
- // Returns:
- // The name of the popup menu script.
- //
-
- // Lookup the name of the popup menu script in the lookup table
- //
- global string $gCollectionUILookupTable[];
-
- return lookupTableLookup(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "popupMenuScript");
- }
-
- global proc collectionUISetPopupMenuScript(
- string $collectionUI,
- string $scriptName)
- {
- //
- // Description:
- // This procedure sets the popup menu script which is invoked when the
- // user RMB clicks in the hyperShade element of the specified collectionUI
- // component. The script will be called with two arguments: the name of
- // the hyperShade editor from which the menu was invoked, and the name of
- // the popupMenu object to which the menu items are to be added.
- //
- // If $scriptName is "", no popup menu will be invoked when the user RMB
- // clicks in the hyperShade editor.
- //
-
- // Find the name of the control that the menu will be attached to
- //
- string $hypershadeName = lookupHypershadeName($collectionUI);
-
- string $parent = `hyperGraph -query -control $hypershadeName`;
- string $popupMenuName = ($hypershadeName + "PopupMenu");
-
- if ($scriptName == "")
- {
- if (`popupMenu -exists $popupMenuName`)
- {
- deleteUI $popupMenuName;
- }
- }
- else
- {
- // Create the popup menu
- //
- if (!`popupMenu -exists $popupMenuName`)
- {
- string $fullMenuName = `popupMenu -parent $parent $popupMenuName`;
- popupMenu
- -edit
- -postMenuCommand
- ($scriptName
- + " "
- + $hypershadeName
- + " "
- + $popupMenuName)
- $fullMenuName;
- }
- }
-
- // Store the name of the popup menu script in the lookup table
- //
- // ASSUMPTION:
- // We assume that a row already exists for this collectionUI, as it should
- // have been created by a call to registerCollectionUI() as the UI was being
- // created.
- //
- global string $gCollectionUILookupTable[];
-
- lookupTableEdit(
- $gCollectionUILookupTable,
- "collectionUI",
- $collectionUI,
- "popupMenuScript",
- $scriptName);
- }
-
- global proc collectionUISetFilter(
- string $collectionUI,
- string $filter)
- {
- //
- // Description:
- // This procedure sets the filter which defines what nodes will appear in
- // the specified collectionUI component.
- //
-
- string $hypershadeName = lookupHypershadeName($collectionUI);
-
- registerFilter($collectionUI, $filter);
-
- if ($filter == "Materials")
- {
- visor
- -addFolder
- -name "Materials"
- -type command
- -cmd "sort `lsThroughFilter DefaultMaterialsFilter`"
- $hypershadeName;
- }
- else if ($filter == "MaterialsAndShaderGlow")
- {
- visor
- -addFolder
- -name "Materials and Shader Glow"
- -type command
- -cmd "sort `ls -type shaderGlow -materials`"
- $hypershadeName;
- }
- else if ($filter == "Textures")
- {
- visor
- -addFolder
- -name "Textures"
- -type command
- -cmd "sort `lsThroughFilter DefaultTexturesFilter`"
- $hypershadeName;
- }
- else if ($filter == "Cameras")
- {
- visor
- -addFolder
- -name "Cameras"
- -type command
- -cmd "sort `lsThroughFilter DefaultCameraShapesImagePlanesFilter`"
- $hypershadeName;
- }
- else if ($filter == "Utilities")
- {
- visor
- -addFolder
- -name "Utilities"
- -type command
- -cmd "sort `lsThroughFilter DefaultRenderUtilitiesFilter`"
- $hypershadeName;
- }
- else if ($filter == "Lights")
- {
- visor
- -addFolder
- -name "Lights"
- -type command
- -cmd "sort `lsThroughFilter DefaultAllLightsFilter`"
- $hypershadeName;
- }
- else if ($filter == "LightsAndOpticalFX")
- {
- visor
- -addFolder
- -name "Lights and Optical FX"
- -type command
- -cmd "sort `lsThroughFilter DefaultLightsAndOpticalFXFilter`"
- $hypershadeName;
- }
- else if ($filter == "ShadingGroups")
- {
- visor
- -addFolder
- -name "Shading Groups"
- -type command
- -cmd "sort `lsThroughFilter DefaultShadingGroupsFilter`"
- $hypershadeName;
- }
- else if ($filter == "PostProcess")
- {
- visor
- -addFolder
- -name "Post Process"
- -type command
- -cmd "sort `ls -type opticalFX -type shaderGlow`"
- $hypershadeName;
- }
- else if ($filter == "BakeSets")
- {
- visor
- -addFolder
- -name "Baking Sets"
- -type command
- -cmd "sort `lsThroughFilter DefaultBakeSetsFilter`"
- $hypershadeName;
- }
- else if ($filter == "CharacterClips")
- {
- visor
- -addFolder
- -name "Character Clips"
- -type command
- -cmd "currentCharacterClips"
- $hypershadeName;
- }
- else if ($filter == "CharacterPoses")
- {
- visor
- -addFolder
- -name "Character Poses"
- -type command
- -cmd "currentCharacterPoses"
- $hypershadeName;
- }
- else if ($filter == "UnusedClips")
- {
- visor
- -addFolder
- -name "Unused Clips"
- -type command
- -cmd "unusedClips"
- $hypershadeName;
- }
- else if ($filter == "UnusedPoses")
- {
- visor
- -addFolder
- -name "Unused Poses"
- -type command
- -cmd "unusedPoses"
- $hypershadeName;
- }
- else
- {
- error ("Unrecognized filter type: " + $filter);
- }
- }
-
- // ---------------------------------------------------------------------------
- // Procedures for creating and deleting a graph UI
- //
-
- global proc collectionUIDelete(
- string $collectionUI,
- int $alsoDeleteHypershade)
- {
- //
- // Description:
- // This procedure deletes all UI associated with the specified
- // collectionUI component.
- // If $alsoDeleteHypershade is true, the hyperShade editor associated
- // with the collectionUI component is also deleted. If
- // $alsoDeleteHypershade is false, the hyperShade editor is simply
- // unparented from the layout and will persist after the layout has been
- // deleted. Typically you would want to do this if you were deleting
- // the collectionUI component but planned to create an identical new one.
- // By not deleting the hyperShade editor, you will be able to reparent
- // it to the new collectionUI component, hence preserving the state of
- // things being displayed by that editor. See the description in
- // collectionUI() for more details.
- //
-
- if (!$alsoDeleteHypershade)
- {
- // The caller has asked us not to delete the hypershade object along
- // with the UI, so we unparent it from the UI before we delete the UI.
- //
- string $hypershadeName = lookupHypershadeName($collectionUI);
- hyperGraph -edit -unParent $hypershadeName;
- }
-
- deleteUI $collectionUI;
- }
-
- global proc string collectionUI(
- string $parentFormLayout,
- string $hypershadeName)
- {
- //
- // Description:
- // This procedure is called from any piece of UI which wants to create a
- // collection UI within itself.
- // This procedure creates the collection UI.
- // If the stateDescription is specified, this code will use it to create
- // a UI with the characteristics described therein.
- // In particular, this is designed to allow the collection UI to be moved
- // from layout to layout without dramatically changing its appearance.
- // Otherwise (if no stateDescription is provided), new UI is created with
- // the default configuration.
- // The $reuseEditors argument is used to specify whether the hyperShade
- // editor whose name is contained in the $stateDescription should be
- // parented to the new UI rather than creating a new hyperShade editor.
- //
- // Returns:
- // This method returns the name of the UI which should be stored by the
- // caller for later use in performing operations on the collection UI.
- //
-
- // Create the lookup table if it does not already exist.
- //
- createCollectionUILookupTable();
-
- if ($hypershadeName == "")
- {
- // There is no existing hyperShade editor to reuse, so we will create a
- // new one.
- //
- $hypershadeName = generateUniqueHypershadeName();
- hyperGraph -unParent $hypershadeName;
- hyperGraph
- -edit
- -zoom 0.75
- $hypershadeName;
- hyperShade
- -setAllowsRegraphing false
- $hypershadeName;
- hyperUserInit($hypershadeName);
- }
-
- string $collectionUI;
-
-
- $collectionUI = `formLayout collection`;
- // Register the collectionUI in the lookup table
- //
- registerCollectionUI($collectionUI);
- registerHypershadeName($collectionUI, $hypershadeName);
-
- hyperGraph
- -edit
- -parent $collectionUI
- $hypershadeName;
-
- formLayout
- -edit
- -af $hypershadeName top 0
- -af $hypershadeName bottom 0
- -af $hypershadeName left 0
- -af $hypershadeName right 0
- $collectionUI;
- setParent ..; // from $collectionUI
- formLayout
- -edit
- -af $collectionUI top 0
- -af $collectionUI bottom 0
- -af $collectionUI left 0
- -af $collectionUI right 0
- $parentFormLayout;
-
- return $collectionUI;
- }
-
-